#include <mutex>
// 可行但 低效
// T *GetInstance(){

//     std::lock_guard guard(_lock);
//     if(_obj == nullptr)
//     {
//         _obj = new Single();

//     }
//     return _obj;
// }
template<class T>
class Single1
{
    private:
        Single1() =default;
        Single1(const Single1& other) = delete;
        Single1& operator=(const Single1& other) = delete;
        static T *_obj;
        static std::mutex _lock;
    public:
        static T *GetInstance(){

            if(_obj == nullptr)
            {
                std::lock_guard guard(_lock);
                if(_obj == nullptr){
                    _obj = new T();
                }
            }
            return _obj;
        }
};
template<class T>
T* Single1<T>::_obj = nullptr;
template<class T>
std::mutex Single1<T>::_lock;

template<class T>
class Single2
{
    private:
        Single2(const Single2& ohter)= delete;
        Single2& operator=(const Single2& other) = delete;
    public:
        static T *getInstance(){
            static T ins;
            return &ins;
        }
};
int main(){
    int *p1 = Single2<int>::getInstance() ;
    int *p2 = Single2<int>::getInstance() ;
    int *p3 = Single2<int>::getInstance() ;
    *p1 = 3;
    *p2 = 4;
    *p3 = 5;
    return 0;
}